package com.gomo.adapter;

import java.util.ArrayList;

import com.gomo.R;
import com.gomo.entity.Cc;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CcAdapter extends BaseAdapter {
	public int count = 10;
	private Activity activity;
	private ArrayList<Cc> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public CcAdapter(Activity a, ArrayList<Cc> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.cc_row, null);
		TextView textName = (TextView) vi.findViewById(R.id.cc_row_text_name);
		ImageView image = (ImageView) vi.findViewById(R.id.cc_row_image);
		Cc item = data.get(position);
		if (textName != null) {
			if (item != null) {
				textName.setText(item.getName());
			} else {
				textName.setText("No name");
			}
		}

		if (image != null) {
			if (item != null) {
				imageLoader.DisplayImage(item.getBankLogo(), activity, image);
			} else {
			}
		}
		return vi;
	}
}
